//
//  XWHAQAReplyTBCell.swift
//  XiaoweHearingAid
//
//  Created by edy on 2024/11/9.
//

import UIKit

extension XWHAQAReplyTBCell {
    class var margin: CGFloat {
        16
    }
    class var titleHeight: CGFloat {
        20
    }
    class var padding: CGFloat {
        10
    }
    class var textContentMargin: CGFloat {
        16 + 10
    }
    class var imageHeight: CGFloat {
        60
    }
    class var textFont: UIFont {
//        AppFont.harmonyOSSans(ofSize: 12, weight: .regular)
        AppFont.harmonyOSSans(ofSize: 16, weight: .regular)
    }
}

class XWHAQAReplyTBCell: XWHComLineBaseTBCell {
    
    lazy var textContentView = XWHATextContentView()
    
    override func addSubViews() {
        super.addSubViews()
        
        contentView.addSubview(textContentView)
                
        bringLineViewToFront()
        
        iconView.image = nil
        subIconView.image = nil
        
        topLine.isHidden = true
        bottomLine.isHidden = true
        
        topLine.backgroundColor = tableSeparatorColor
        bottomLine.backgroundColor = tableSeparatorColor
        
        textContentView.layer.cornerRadius = 7
        textContentView.layer.backgroundColor = UIColor(hex: 0xD5E9FF).cgColor
                
        var tFont = AppFont.harmonyOSSans(ofSize: 16, weight: .regular)
        titleLb.font = tFont
        titleLb.textColor = btnBgColor
        titleLb.textAlignment = .left
        
        tFont = AppFont.harmonyOSSans(ofSize: 14, weight: .regular)
        subTitleLb.font = tFont
        subTitleLb.textColor = minorTextColor
        subTitleLb.textAlignment = .left
//        subTitleLb.adjustsFontSizeToFitWidth = true
        
        textContentView.textLb.font = Self.textFont
        textContentView.textLb.textAlignment = .right
        textContentView.textLb.numberOfLines = 0
        
        titleLb.text = "验配师回复"
        subTitleLb.text = ""
        
        textContentView.textLb.text = ""
    }
    
    override func relayoutSubViews() {
        relayoutTitleSubTitleLb(isLeft: false)
        textContentView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(Self.margin)
            make.top.equalTo(subTitleLb.snp.bottom).offset(4)
            make.bottom.equalToSuperview().inset(4)
        }
        relayoutTopBottomLine()
    }
    
    func relayoutTitleSubTitleLb(isLeft: Bool) {
        if isLeft {
            titleLb.snp.remakeConstraints { make in
                make.height.equalTo(Self.titleHeight)
                make.left.equalToSuperview().inset(Self.margin)
                make.top.equalToSuperview().inset(Self.margin)
                make.width.lessThanOrEqualTo(140)
            }
            subTitleLb.snp.remakeConstraints { make in
                make.height.centerY.equalTo(titleLb)
                make.left.equalTo(titleLb.snp.right).offset(4)
                make.width.lessThanOrEqualTo(240)
            }
        } else {
            titleLb.snp.makeConstraints { make in
                make.height.equalTo(Self.titleHeight)
                make.right.equalToSuperview().inset(Self.margin)
                make.top.equalToSuperview().inset(Self.margin)
                make.width.lessThanOrEqualTo(140)
            }
            subTitleLb.snp.makeConstraints { make in
                make.height.centerY.equalTo(titleLb)
                make.right.equalTo(titleLb.snp.left).offset(-4)
                make.width.lessThanOrEqualTo(240)
            }
        }
    }
    
    override func relayoutTopBottomLine() {
        topLine.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.height.equalTo(0.5)
            make.left.equalToSuperview().offset(16)
            make.right.equalToSuperview().offset(-16)
        }
        
        bottomLine.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.height.equalTo(0.5)
            make.left.equalToSuperview().offset(16)
            make.right.equalToSuperview().offset(-16)
        }
        
        bringLineViewToFront()
    }
    
    func update(info: XWHAQAModel) {
        titleLb.text = "验配师\(info.name)"
        subTitleLb.text = info.createdAt
        textContentView.textLb.text = info.content
    }

}
